package com.zmx.common.common.web.rest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: Controller控制器全局异常统一返回数据
 * @ClassName: RestExcetionHandler
 * @Author zhaomxr
 * @Date 2021-10-09 16:23
 */
@Slf4j
@RestControllerAdvice
public class RestExceptionHandler {

    /**
     * 全局异常统一处理
     *
     * @param e 全局异常
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public <T> ResponseResult<T> exception(Exception e) {
        log.error("系统调用异常", e);
        return ResponseResult.fail(e.getMessage());
    }
}
